Hello, string Original = "Hello World" print "Original [" Original "]\n" // Encode it string Encoded toBase64_(Original, Encoded) print "Encoded [" Encoded "]\n" // Decoded it string Decoded fromBase64_(Encoded, Decoded) print "Decoded [" Decoded "]\n" // Decoded length int DecodedLength = length(Original) print "DecodedLength : " DecodedLength "\n" // Fix using the Decoded length string Fixed = Decoded[0:DecodedLength-1] print "Fixed [" Fixed "]\n"
Original [Hello World] Encoded [SGVsbG8gV29ybGQ= ] Decoded [Hello WorldybGQ= ] DecodedLength : 11 Fixed [Hello World]
SystemAdmin - Mon Apr 30 04:32:45 EDT 2012 |
Re: Decoding Base64
Doh! I screwed up. I'm getting the length of the original, not the decoded! int DecodedLength = length(Original) //oops
|
Re: Decoding Base64 These functions seems to be bugged since they do not return the same results each time. Run the following over and over:
string NoEOL(string InString)
{ int Len = length(InString)
if (InString[Len-1] == '\n') //
then return(InString[0:Len-2] "@")
else return(InString)
}
void fDecodeBullCrap(string Encoded, &Decoded)
{ int i, LenMin = -1, Len
string DecodedTemp = ""
//fromBase64_(Encoded Encoded, DecodedTemp)
for (i=0; i<100; i++)
{ fromBase64_(DecodedTemp, DecodedTemp)
//toBase64_ (Encoded, DecodedTemp)
fromBase64_(Encoded, DecodedTemp)
Len = length(DecodedTemp)
if (LenMin == -1 or Len < LenMin) LenMin = Len
//print "\t" Len "\t" LenMin "\t[" (NoEOL(DecodedTemp)) "]\n"
}
Decoded = DecodedTemp[0:LenMin-1]
}
void DoTest(string Original)
{ string Encoded = "", Decoded = ""
toBase64_(Original, Encoded)
fDecodeBullCrap(Encoded, Decoded)
bool Success = Original == Decoded
print Success "\t[" Original "]\t^" (NoEOL(Encoded)) "^\t[" (NoEOL(Decoded)) "]\n"
}
DoTest("Hello Word") // Not "Hallo"
DoTest("AA")
DoTest("AAx d")
|
Re: Decoding Base64 llandale - Mon Apr 30 11:03:24 EDT 2012 These functions seems to be bugged since they do not return the same results each time. Run the following over and over:
string NoEOL(string InString)
{ int Len = length(InString)
if (InString[Len-1] == '\n') //
then return(InString[0:Len-2] "@")
else return(InString)
}
void fDecodeBullCrap(string Encoded, &Decoded)
{ int i, LenMin = -1, Len
string DecodedTemp = ""
//fromBase64_(Encoded Encoded, DecodedTemp)
for (i=0; i<100; i++)
{ fromBase64_(DecodedTemp, DecodedTemp)
//toBase64_ (Encoded, DecodedTemp)
fromBase64_(Encoded, DecodedTemp)
Len = length(DecodedTemp)
if (LenMin == -1 or Len < LenMin) LenMin = Len
//print "\t" Len "\t" LenMin "\t[" (NoEOL(DecodedTemp)) "]\n"
}
Decoded = DecodedTemp[0:LenMin-1]
}
void DoTest(string Original)
{ string Encoded = "", Decoded = ""
toBase64_(Original, Encoded)
fDecodeBullCrap(Encoded, Decoded)
bool Success = Original == Decoded
print Success "\t[" Original "]\t^" (NoEOL(Encoded)) "^\t[" (NoEOL(Decoded)) "]\n"
}
DoTest("Hello Word") // Not "Hallo"
DoTest("AA")
DoTest("AAx d")
Well, I suppose the functions are undocumented. I just wonder about the competance of the developers if a function like this gets into released software. Do they not do unit tests of their functions?? It took me one try to realise it dosen't work. This is something that should be really easy to implement and test. And if it fails, don't release it! I hope it isn't being used internally... I wonder if it is used with OLEs and causes the sporadic corruption. |
Re: Decoding Base64 SystemAdmin - Mon Apr 30 11:40:06 EDT 2012 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: Decoding Base64 Mathias Mamsch - Tue May 08 11:58:03 EDT 2012 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: Decoding Base64 Hi, To export an OLE from Doors to Word, I do as following:
I select the OLE and I put it in a file ( I use: exportPicture(ole,filename , formatPNG))
I put the contain of the file into a stream and then into a buffer.( I use: Stream inStream = read binary inFile)
I use the function "_BASE64" to convert the content of the buffer to BASE64 .
Then I put the _BASE64 content into the XML script.
But it doesn't work.. Can you help me?.
Thank you. //////////////////////////////////// This is my code:
void readBinaryFile(string NameFile, Buffer b)
{
Stream x = read (binary (NameFile))
char c
while(true)
{
x >> c
if (end x)
break
else { b += c}
}
close x
}
void CheckisOLE (Object obj)
{
EmbeddedOleObject ole
RichText rtf
string s = richTextWithOle obj."Object Text"
string filename
Buffer b = create()
for rtf in s do
{
if (rtf.isOle)
{
//Mémorisation des OLE sous forme d'image.
ole = rtf.getEmbeddedOle
string filename = "C:\\essai-rtfloop-.png"
print "Exporting " filename "\n"
exportPicture(ole,filename , formatPNG)
// Read the image content
readBinaryFile(filename, b)
string outpstr = ""
print "bufferB content is equal to:" b "\n"
outpstr = stringOf(b)
setempty b
print "outpstr content is equal to:" outpstr "\n" "\n" "\n"
//Coding the content on base64
string Encoded1 = ""
toBase64_(outpstr, Encoded1)
print "Encoded1 content is equal to:" Encoded1 "\n" "\n" "\n"
//displaying it on xml.
AddBuffer("<w:pict>")
AddBuffer("<w:binData w:name=\"wordml://03000001.png\" xml:space=\"preserve\">")
AddBuffer(Encoded1)
AddBuffer("</w:binData>")
AddBuffer("<v:shape>")
AddBuffer("<v:imagedata src=\"wordml://03000001.png\" o:title=\"\"/>")
AddBuffer("</v:shape>")
AddBuffer("</w:pict>")
}
|
Re: Decoding Base64 Karray - Wed Sep 04 10:16:00 EDT 2013 Hi, To export an OLE from Doors to Word, I do as following:
I select the OLE and I put it in a file ( I use: exportPicture(ole,filename , formatPNG))
I put the contain of the file into a stream and then into a buffer.( I use: Stream inStream = read binary inFile)
I use the function "_BASE64" to convert the content of the buffer to BASE64 .
Then I put the _BASE64 content into the XML script.
But it doesn't work.. Can you help me?.
Thank you. //////////////////////////////////// This is my code:
void readBinaryFile(string NameFile, Buffer b)
{
Stream x = read (binary (NameFile))
char c
while(true)
{
x >> c
if (end x)
break
else { b += c}
}
close x
}
void CheckisOLE (Object obj)
{
EmbeddedOleObject ole
RichText rtf
string s = richTextWithOle obj."Object Text"
string filename
Buffer b = create()
for rtf in s do
{
if (rtf.isOle)
{
//Mémorisation des OLE sous forme d'image.
ole = rtf.getEmbeddedOle
string filename = "C:\\essai-rtfloop-.png"
print "Exporting " filename "\n"
exportPicture(ole,filename , formatPNG)
// Read the image content
readBinaryFile(filename, b)
string outpstr = ""
print "bufferB content is equal to:" b "\n"
outpstr = stringOf(b)
setempty b
print "outpstr content is equal to:" outpstr "\n" "\n" "\n"
//Coding the content on base64
string Encoded1 = ""
toBase64_(outpstr, Encoded1)
print "Encoded1 content is equal to:" Encoded1 "\n" "\n" "\n"
//displaying it on xml.
AddBuffer("<w:pict>")
AddBuffer("<w:binData w:name=\"wordml://03000001.png\" xml:space=\"preserve\">")
AddBuffer(Encoded1)
AddBuffer("</w:binData>")
AddBuffer("<v:shape>")
AddBuffer("<v:imagedata src=\"wordml://03000001.png\" o:title=\"\"/>")
AddBuffer("</v:shape>")
AddBuffer("</w:pict>")
}
The problem is null 'characters' in the binary stream terminating the Buffer. See this thread.
|
Re: Decoding Base64 Adamarla - Thu Sep 05 03:47:02 EDT 2013 The problem is null 'characters' in the binary stream terminating the Buffer. See this thread.
Thanks for your help,
Yes, null 'characters' is the problem.
In the thread "Read picture data to buffer?'", I see a solution to read and write the same picture.
But in my case I want to recuperate the "binary + null 'characters'" and transmit all datas to the function _BASE64.
This is the part of code where ther are a problem:
// Read the image content
readBinaryFile(filename, b) ////// IN THIS PART Buffer b doesn't recuperate the null 'character
string outpstr = ""
print "bufferB content is equal to:" b "\n"
outpstr = stringOf(b)
setempty b
print "outpstr content is equal to:" outpstr "\n" "\n" "\n"
//Coding the content on base64
string Encoded1 = ""
toBase64_(outpstr, Encoded1) ////// IN THIS PART ENCODING IS INCORRECT
print "Encoded1 content is equal to:" Encoded1 "\n" "\n" "\n"
Can you help me? |
Re: Decoding Base64 Karray - Thu Sep 05 05:19:51 EDT 2013
Thanks for your help,
Yes, null 'characters' is the problem.
In the thread "Read picture data to buffer?'", I see a solution to read and write the same picture.
But in my case I want to recuperate the "binary + null 'characters'" and transmit all datas to the function _BASE64.
This is the part of code where ther are a problem:
// Read the image content
readBinaryFile(filename, b) ////// IN THIS PART Buffer b doesn't recuperate the null 'character
string outpstr = ""
print "bufferB content is equal to:" b "\n"
outpstr = stringOf(b)
setempty b
print "outpstr content is equal to:" outpstr "\n" "\n" "\n"
//Coding the content on base64
string Encoded1 = ""
toBase64_(outpstr, Encoded1) ////// IN THIS PART ENCODING IS INCORRECT
print "Encoded1 content is equal to:" Encoded1 "\n" "\n" "\n"
Can you help me? Can you help me? I am Blocked ! Thank you. |